<?php

namespace app\common\exception;

use think\exception\ValidateException;
use think\facade\Env;
use think\queue\command\Retry;
use think\Response;
use think\exception\HttpException;
use think\exception\Handle;
use think\Request;

class Http extends Handle
{
    public function render(Request $request, \Throwable $e): Response
    {
//        echo "<pre>";
//        print_r($e instanceof HttpException);
//        exit;
        // 参数验证错误
        if ($e instanceof ValidateException) {
            return error(msg:$e->getMessage());
        }

        // 请求异常
        if ($request->isAjax()) {
            if(Env::get('app_debug', false)){
                return error($e->getMessage(),0,$e->getTrace());
            }else{
                return error($e->getMessage());
            }
        }

        // 其他错误交给系统处理
        return parent::render($request, $e);
    }
}